package des.yordan.mihaylov;

/**
 * @author Yordan Mihaylov
 * @version 2011/06/05
 */

public class ServiceCompletion extends SimEvent {

	public ServiceCompletion(long simulationTime) {
		super(simulationTime);
	}

	public void process() {

		long now = simState.getNow();

		// if customers are waiting
		if (!simState.isQueueEmpty()) {
			long serviceCompletionTime = now + simState.getServiceTime();
			// process next customer
			simState.nextCustomer(serviceCompletionTime);
			simState.calcCustomerStats();
			simState.waitingQueueLength.count(-1.);
			simState.enqueueEvent(new ServiceCompletion(serviceCompletionTime));
		} else {
			// go to idle
			simState.setServerBusy(false);
			// set the current time as start of an idle period
			simState.utilization.setFirstSampleTime(now);
		}
	}
}
